package com.zs.demo.controller.system;

import com.baomidou.mybatisplus.plugins.Page;
import com.zs.demo.common.log.SysLogAop;
import com.zs.demo.common.response.CommonStatus;
import com.zs.demo.common.response.IResponseStatus;
import com.zs.demo.pojo.dto.system.role.FindRoleDTO;
import com.zs.demo.pojo.dto.system.role.RoleAddDTO;
import com.zs.demo.pojo.dto.system.role.RoleUpdateDTO;
import com.zs.demo.pojo.entity.system.SysRole;
import com.zs.demo.service.system.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;



/**
 * @author Licoy
 * @version 2018/4/19/9:41
 */
@RestController
@RequestMapping(value = {"/system/role"})
@Api(tags = {"角色管理"})
public class RoleController{

    @Autowired
    private SysRoleService sysRoleService;

    @PostMapping("/list")
    @ApiOperation(value = "分页获取所有列表")
    @ApiImplicitParam(paramType = "header",name = "Authorization",value = "身份认证Token",required = true)
    public Page<SysRole> list(@RequestBody FindRoleDTO findDTO){
        return sysRoleService.list(findDTO);
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加新增")
    @SysLogAop("添加新增")
    @ApiImplicitParam(paramType = "header",name = "Authorization",value = "身份认证Token",required = true)
    public IResponseStatus add(@RequestBody @Validated RoleAddDTO a){
        sysRoleService.add(a);
        return CommonStatus.OK;
    }

    @PostMapping("/update/{id}")
    @ApiOperation(value = "更新指定ID对象的信息")
    @SysLogAop("更新指定ID对象的信息")
    @ApiImplicitParam(paramType = "header",name = "Authorization",value = "身份认证Token",required = true)
    public IResponseStatus update(@PathVariable("id") String id, @RequestBody @Validated RoleUpdateDTO updateDTO){
        sysRoleService.update(id,updateDTO);
        return CommonStatus.OK;
    }

    @PostMapping("/remove/{id}")
    @ApiOperation(value = "删除指定ID的对象")
    @SysLogAop("删除指定ID的对象")
    @ApiImplicitParam(paramType = "header",name = "Authorization",value = "身份认证Token",required = true)
    public IResponseStatus remove(@PathVariable("id") String id){
        sysRoleService.remove(id);
        return CommonStatus.OK;
    }
}
